﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Kristall.Engine;
using Kristall.Engine.Scripts;

namespace Kristall.MyGame.Scripts
{
    public class LavaScript : Script
    {
        public float Damage
        {
            get;
            set;
        }

        [XmlIgnore]
        public string SoundCue
        {
            get;
            set;
        }

        public LavaScript()
            : base()
        {
            Damage = 0.1f;
            SoundCue = @"Sizzle";
        }

        public override void Load(Level level, AABB aabb)
        {
            aabb.OnCollision += new EventHandler<CollisionEventArgs>(aabb_OnCollision);
        }

        void aabb_OnCollision(object sender, CollisionEventArgs e)
        {
            if (!this.Enabled)
                return;

            Actor other;

            if ((other = e.Other as Actor) != null)
            {
                Kristall.SoundManager.PlayNonInstancedSound(SoundCue);
                other.Health -= Damage;
            }
        }
    }
}
